import urllib
from sgmllib import SGMLParser
import htmlentitydefs


class HrefParser(SGMLParser):
    def __init__(self,url):
        SGMLParser.__init__(self)
        sock = urllib.urlopen(url)
        self.feed(sock.read())
        sock.close()
        
    def set_url(self, url):
        self.url = url
        
        
    def reset(self):
        self.href_list = []
        SGMLParser.reset(self)

    def start_a(self,attr):
        href = [v for i,v in attr if i == 'href']
        if href:
            self.href_list.extend(href)

    def get_href_list(self):
        return self.href_list


if __name__ == '__main__':
    href_parser = HrefParser("http://192.168.13.22")
    print href_parser.get_href_list()
    href_parser.close()
